home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8521 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  46 lines

  1. Path: dfw.dfw.net!not-for-mail
  2. From: ftlgeuse@dfw.dfw.net (Fetelgeuse)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Hiding a password
  5. Date: 4 Mar 1996 10:46:37 GMT
  6. Organization: DFW Internet Services - DFWNet: 800-2-DFWNet
  7. Message-ID: <4hehmd$1fr@fnord.dfw.net>
  8. References: <1996Feb29.224936.137160@forest> <4he620$qf2@hpbblb.bbn.hp.com>
  9. NNTP-Posting-Host: dfw.dfw.net
  10. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  11.  
  12. Matthias Dittrich (matti) wrote:
  13. : ebromber@forest.drew.edu wrote:
  14. : >I recently wrote a password program. However, there is one little flaw I 
  15. : >want to fix. When the password is entered, it is visible on the screen. I 
  16. : >was wondering if anyone knows how to hide the password by  printing 
  17. : >asterisks instead of the actual character. 
  18. : >Thanks in advance.
  19. : >
  20. : Switch echo off using ioctl function and if you want so, write asterisks
  21. : on your terminal.
  22. : Good luck,
  23. : Matthias
  24. I wrote a function to do precisely the same thing. I made a function
  25. something like:
  26. char * GetString_NoEcho()
  27. {
  28.   char *temp;
  29.   int i=1;
  30.   while(temp[i-1]!=13) {
  31.     temp[i-1]=getch();  
  32.     i++;
  33.   }
  34.   temp[i]=0;
  35. }
  36. I haven't really thought that out real well so you might find that the 
  37. string index is the wrong value for any given character position but that
  38. would be easily fixed (if it is off, it would be off by 1 position) What 
  39. it should do is place the return value of a series of getch()'s into temp[0],
  40. temp[1],temp[...], until the user enters [enter] and then where enter was 
  41. gets replaced by a null. Anyway, like I said the indexes may be off but 
  42. this way works when done properly.
  43.     
  44.